package com.xdja;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * hhz
 */
public class Joseph {
    public static void main(String[] args) {
        joseph(41, 3);
    }

    public static void joseph(int totalCount, int intervalCount) {
        List<Integer> list = new ArrayList<>();
        for (int i = 1; i <= totalCount; i ++) {
            list.add(i);
        }

        Iterator<Integer> iterator;
        int index = 0;
        while (list.size() > 1) {
            iterator = list.iterator();
            while (iterator.hasNext()) {
                Integer survivor = iterator.next();
                index ++;
                if (index == intervalCount) {
                    System.out.println(survivor + "!!!!! you're unlucky");
                    iterator.remove();
                    index = 0;
                }
            }

        }

        System.out.println(list.get(0) + "!!! Congratulations you are the one.");
    }
}
